package com.lfy.modules.letter.controller;

import com.lfy.modules.common.anno.Authentication;
import com.lfy.modules.common.domain.R;
import com.lfy.modules.letter.domain.dto.FeedLetterDTO;
import com.lfy.modules.letter.domain.dto.GlobalLetterDTO;
import com.lfy.modules.letter.domain.dto.LetterDTO;
import com.lfy.modules.letter.domain.vo.FeedLetterVO;
import com.lfy.modules.letter.domain.vo.GlobalLetterVO;
import com.lfy.modules.letter.domain.vo.LetterVO;
import com.lfy.modules.letter.domain.vo.SysLetterVO;
import com.lfy.modules.letter.service.SiteLetterService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/letter")
public class LetterController {
    @Resource
    private SiteLetterService letterService;

    /**
     * 获取站内信列表
     * @return R<SysLetterVO>
     */
    @GetMapping("/get/list")
    public R<SysLetterVO> getLetterList() {
        return letterService.getLetterList();
    }

    /**
     * 向下滑动获取站内信列表
     * @param length 已有数量
     * @return R<List<LetterVO>>
     */
    @GetMapping("/get/sys/Letter")
    public R<List<LetterVO>> getSysLetter(@RequestParam("length") Integer length) {
        return letterService.getSysLetter(length);
    }

    /**
     * 向下滑动获取全局信列表
     * @param length 已有数量
     * @return R<List<GlobalLetterVO>>
     */
    @GetMapping("/get/global/Letter")
    public R<List<GlobalLetterVO>> getGlobalLetter(@RequestParam("length") Integer length) {
        return letterService.getGlobalLetter(length);
    }
    /**
     * 发送全局信
     */
    @PostMapping("/send/global/Letter")
    @Authentication("sys:send:user:letter")
    public R<Void> sendGlobalLetter(@RequestBody @Validated GlobalLetterDTO globalLetterDTO) {
        return letterService.sendGlobalLetter(globalLetterDTO);
    }
    /**
     * 发送站内信
     */
    @PostMapping("/send/sys/Letter")
    @Authentication("sys:send:user:letter")
    public R<Void> sendSysLetter(@RequestBody @Validated LetterDTO dto) {
        return letterService.sendSysLetter(dto);
    }
    /**
     * 向站长发送反馈信
     */
    @PostMapping("/send/feedback/Letter")
    @Authentication("sys:send:feed:letter")
    public R<Void> sendFeedbackLetter(@RequestBody @Validated FeedLetterDTO dto) {
        return letterService.sendFeedbackLetter(dto);
    }
    /**
     * 查看反馈信列表
     */
    @GetMapping("/get/feedback/Letter")
    @Authentication("sys:get:feed:letter")
    public R<List<FeedLetterVO>> getFeedbackLetter() {
        return letterService.getFeedbackLetter();
    }
    @PostMapping("/remove/feedback/Letter")
    @Authentication("sys:remove:feed:letter")
    public R<Void> removeFeedbackLetter() {
        return letterService.removeFeedbackLetter();
    }
}
